package com.rd.student.ruanjian.class4.zhouzihe.day17;

import java.io.File;
import java.io.IOException;

public class TestFile {
    public static void main(String[] args) {
        String path = "D:\\.metadata";
        String path1 = System.getProperty("user.dir");
        System.out.println(path1);

        String filePath = path1 + "\\" + "text";
        System.out.println(filePath);

        String filePatht1 = path1 + File.separator + "text";
        System.out.println(filePatht1);

        File file = new File(filePath);
        System.out.println(file);
        System.out.println("------");
        //构造器传入的路径
        System.out.println(file.getPath());
        //绝对路径
        System.out.println(file.getAbsolutePath());

        //判断文件是文件本身还是文件夹
        System.out.println(file.isFile());
        System.out.println(file.isDirectory());

        File dir = new File(path1 + "\\" + "file");
        System.out.println(dir.isDirectory());
        System.out.println(dir.isFile());

        //权限 可读可写可执行
        System.out.println(file.canRead());
        System.out.println(file.canWrite());
        System.out.println(file.canExecute());

        //创建和删除文件
        File newFile = new File(dir + "\\" + "test1.txt");
        try {

            Boolean result = newFile.createNewFile();
            if (result) {
                System.out.println("创建文件成功");
                System.out.println(newFile);
                return;
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println("创建文件失败");
        System.out.println(newFile.exists());
    }



}
